package deploy

import (
	v1 "k8s.io/api/apps/v1"
	apiv1 "k8s.io/api/core/v1"
	"time"
	"twwch/k8s-admin/models/service"
)

type ReqBase struct {
	Name      string `json:"name" form:"name"`
	Namespace string `json:"namespace" form:"namespace"`
}

type CreateReq struct {
	ReqBase     `json:",inline"`
	Replicas    int32             `json:"replicas" form:"replicas"`
	Containers  []apiv1.Container `json:"containers" form:"containers"`
	Volumes     []apiv1.Volume    `json:"volumes" form:"volumes"`
	IsCreateSvc bool              `json:"is_create_svc"`
	Service     struct {
		Type service.ServiceType `json:"type" form:"type"`
		//Selector map[string]string   `json:"selector" form:"selector"`
		Ports []apiv1.ServicePort `json:"ports" form:"ports"`
	} `json:"service"`
}

type CreateResp struct {
	Deployment  *CreateDeployInfo   `json:"deployment"`
	Service     *service.CreateResp `json:"service"`
	IsCreateSvc bool                `json:"is_create_svc"`
}

type CreateDeployInfo struct {
	Name string         `json:"name"`
	IsOk bool           `json:"is_ok"`
	Info *v1.Deployment `json:"info"`
}

type DeleteReq struct {
	ReqBase `json:",inline"`
}

type UpdateReq struct {
	ReqBase    `json:",inline"`
	Replicas   int32             `json:"replicas" form:"replicas"`
	Containers []apiv1.Container `json:"containers" form:"containers"`
	Volumes    []apiv1.Volume    `json:"volumes" form:"volumes"`
}

type UpdateResp struct {
	Deployment *CreateDeployInfo `json:"deployment"`
}

type GetReq struct {
	ReqBase `json:",inline"`
}

type GetResp struct {
	Deployment *v1.Deployment `json:"deployment"`
}

type ListReq struct {
	ReqBase `json:",inline"`
}

type ListResp struct {
	Total int64     `json:"total"`
	Items []*Deploy `json:"items"`
}

type Deploy struct {
	DeployName string         `json:"deploy_name" bson:"deploy_name"`
	Namespace  string         `json:"namespace" bson:"namespace"`
	CreateTime time.Time      `json:"create_time" bson:"create_time"`
	Deployment *v1.Deployment `json:"deployment" bson:"deployment"`
}
